package com.dyc.caradvertisting.ui.fmt.tab.store;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

import com.dyc.caradvertisting.R;
import com.dyc.caradvertisting.base.BaseLazyMainFragment;
import com.dyc.caradvertisting.constants.Constant;
import com.njh.tools.base.BaseFragment;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 *
 */
public class StoreFragment extends BaseLazyMainFragment {

    @BindView(R.id.line_all)
    LinearLayout lineAll;
    @BindView(R.id.line_matter)
    LinearLayout lineMatter;
    @BindView(R.id.line_serve)
    LinearLayout lineServe;
    @BindView(R.id.line_ticket)
    LinearLayout lineTicket;
    @BindView(R.id.bnr_adv)
    Banner bnrAdv;
    @BindView(R.id.fmt_goods)
    FrameLayout fmtGoods;
    List<String> adv=new ArrayList<>();
//    List<BaseFragment> baseFragmentList=new ArrayList<>();
    public StoreFragment() {
        // Required empty public constructor
    }

    public static StoreFragment newInstance() {
        StoreFragment fragment = new StoreFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return getView(inflater, container);
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_store;
    }

    @Override
    public void initView(View baseView) {
        ButterKnife.bind(this, baseView);
        initToolbar(R.string.title_shpping);
        adv.add("http://imgsrc.baidu.com/forum/pic/item/f643dc54564e925850c8af029482d158cdbf4e3a.jpg");
        adv.add("http://img4.cache.netease.com/photo/0026/2015-05-19/APVC513454A40026.jpg");
        adv.add("http://attach.bbs.miui.com/forum/201409/05/164828g71ar48xlpy8xzfl.jpg");
        bnrAdv.setDelayTime(4500);
        bnrAdv.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
        bnrAdv.setIndicatorGravity(BannerConfig.CENTER);
        bnrAdv.setImages(adv);
    }

    @Override
    public boolean isSwipeBack() {
        return false;
    }

    @Override
    public void initPresenter() {

    }

    @OnClick({R.id.line_all, R.id.line_matter, R.id.line_serve, R.id.line_ticket})
    public void onClick(View view) {
        lineAll.setSelected(false);
        lineMatter.setSelected(false);
        lineServe.setSelected(false);
        lineTicket.setSelected(false);
        view.setSelected(true);
        switch (view.getId()) {
            case R.id.line_all:
                loadRootFragment(R.id.fmt_goods, GoodsFragment.newInstance(Constant.CATEGORY_ALL));
                break;
            case R.id.line_matter:
                loadRootFragment(R.id.fmt_goods, GoodsFragment.newInstance(Constant.CATEGORY_2));
                break;
            case R.id.line_serve:
                loadRootFragment(R.id.fmt_goods, GoodsFragment.newInstance(Constant.CATEGORY_3));
                break;
            case R.id.line_ticket:
                loadRootFragment(R.id.fmt_goods, GoodsFragment.newInstance(Constant.CATEGORY_4));
                break;
        }
    }

    @Override
    protected void initLazyView(@Nullable Bundle savedInstanceState) {
        lineAll.setSelected(true);
        loadRootFragment(R.id.fmt_goods, GoodsFragment.newInstance(Constant.CATEGORY_ALL));
    }
}
